package laya.util;

public class ProductCode8B extends ProductCode
{
	public ProductCode8B()
	{
		PRODUCTID_MASK		= 0xffff000000000000l;
		VERSION_MASK		= 0x0000ff0000000000l;
		VERSUFF_MASK		= 0x000000ff00000000l;
		BUILDNO_MASK		= 0x00000000ffff0000l;
		RELEASENO_MASK		= 0x000000000000fff0l;
		CHECKCODE_MASK		= 0x000000000000000fl;
		COMPARE_MASK		= ~(BUILDNO_MASK | CHECKCODE_MASK);
	}
	
	public long getCode()
	{
		return 
			((m_nProductID 		& 0x0000ffffl) << (4 * 12))
			| ((m_nVersion		& 0x000000ffl) << (4 * 10))
			| ((m_nVerSuff		& 0x000000ffl) << (4 *  8))
			| ((m_nBuildNo		& 0x0000ffffl) << (4 *  4))
			| ((m_nReleaseType	& 0x00000fffl) << (4 *  1))
			| ((m_nCheckCode	& 0x0000000fl) << (4 *  0));
	}
	public void setCode(long code)
	{
		m_nProductID	= (code >> (4 * 12)) & 0x0000ffffl;
		m_nVersion		= (code >> (4 * 10)) & 0x000000ffl;
		m_nVerSuff		= (code >> (4 *  8)) & 0x000000ffl;
		m_nBuildNo		= (code >> (4 *  4)) & 0x0000ffffl;
		m_nReleaseType	= (code >> (4 *  1)) & 0x00000fffl;
		m_nCheckCode	= (code >> (4 *  0)) & 0x0000000fl;
	}

	public long makeCheckCode()
	{
		return ( m_nProductID 
				 + m_nVersion 
				 + m_nVerSuff 
				 + m_nBuildNo
				 + m_nReleaseType
			   ) & CHECKCODE_MASK;
	}

	public String toHexString(long n)
	{
		String result = "";
		String pre = Long.toHexString(n);
		
		result += getSubCode(pre, 12, 15);
		result += '-' + getSubCode(pre, 10, 11);
		result += '-' + getSubCode(pre, 8, 9);
		result += '-' + getSubCode(pre, 4, 7);
		result += '-' + getSubCode(pre, 1, 3);
		result += '-' + getSubCode(pre, 0, 0);
		
		return result;
	}
}